package com.sgcc.ln.pmos.e_ln_home.activity;

import android.widget.TextView;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.arouter.home.HomeArouterPath;
import com.sgcc.ln.pmos.common.base.MvpBaseActivity;
import com.sgcc.ln.pmos.common.utils.DateUtils;
import com.sgcc.ln.pmos.common.widget.TitleBar;
import com.sgcc.ln.pmos.e_ln_home.adapter.InforDiscloSecondStepAdapter;
import com.sgcc.ln.pmos.e_ln_home.adapter.StructuralInformationAdapter;
import com.sgcc.ln.pmos.e_ln_home.bean.TradingInstitutionBasicinfoBean;
import com.sgcc.ln.pmos.e_ln_home.contract.TradingInstitutionBasicinfoContract;
import com.sgcc.ln.pmos.e_ln_home.presenter.TradingInstitutionBasicinfoPresenter;

import java.util.List;

/**
 * 交易机构基本信息
 */
@Route(path = HomeArouterPath.HOME_TRADINGINSTITUTIONBASICINFO)
public class TradingInstitutionBasicinfoActivity extends MvpBaseActivity<TradingInstitutionBasicinfoPresenter> implements TradingInstitutionBasicinfoContract.View {

    private TitleBar mTitleBar;
    private TextView mTvBusinessLicenseInformation1;
    private TextView mTvBusinessLicenseInformation2;
    private TextView mTvBusinessLicenseInformation3;
    private TextView mTvBusinessLicenseInformation4;
    private TextView mTvBusinessLicenseInformation5;
    private TextView mTvBusinessLicenseInformation6;
    private TextView mTvBusinessLicenseInformation7;
    private TextView mTvBusinessLicenseInformation8;
    private TextView mTvBusinessLicenseInformation9;
    private TextView mTvBusinessLicenseInformation10;
    private TextView mTvBusinessLicenseInformation11;
    private TextView mTvBusinessLicenseInformation12;
    private TextView mTvBusinessLicenseInformation13;
    private TextView mTvBusinessLicenseInformation14;
    private TextView mTvOtherBasicInformation1;
    private TextView mTvOtherBasicInformation2;
    private TextView mTvOtherBasicInformation3;
    private RecyclerView mRvStructuralInformation;
    private StructuralInformationAdapter mStructuralInformationAdapter;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_tradinginstitutionbasicinfo;
    }

    @Override
    protected TradingInstitutionBasicinfoPresenter createPresenter() {
        return new TradingInstitutionBasicinfoPresenter();
    }

    @Override
    protected void initViews() {
        super.initViews();
        findViewByIds();
        mPresenter.getData();
    }

    private void findViewByIds() {
        mTitleBar = (TitleBar) findViewById(R.id.title_bar);
        mTvBusinessLicenseInformation1 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation1);
        mTvBusinessLicenseInformation2 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation2);
        mTvBusinessLicenseInformation3 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation3);
        mTvBusinessLicenseInformation4 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation4);
        mTvBusinessLicenseInformation5 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation5);
        mTvBusinessLicenseInformation6 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation6);
        mTvBusinessLicenseInformation7 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation7);
        mTvBusinessLicenseInformation8 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation8);
        mTvBusinessLicenseInformation9 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation9);
        mTvBusinessLicenseInformation10 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation10);
        mTvBusinessLicenseInformation11 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation11);
        mTvBusinessLicenseInformation12 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation12);
        mTvBusinessLicenseInformation13 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation13);
        mTvBusinessLicenseInformation14 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation14);
        mTvOtherBasicInformation1 = (TextView) findViewById(R.id.tv_OtherBasicInformation1);
        mTvOtherBasicInformation2 = (TextView) findViewById(R.id.tv_OtherBasicInformation2);
        mTvOtherBasicInformation3 = (TextView) findViewById(R.id.tv_OtherBasicInformation3);
        mRvStructuralInformation = (RecyclerView) findViewById(R.id.rv_StructuralInformation);

        mTitleBar.setTitle("交易机构基本信息");

        LinearLayoutManager secondLLManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        mRvStructuralInformation.setLayoutManager(secondLLManager);
        mRvStructuralInformation.setItemAnimator(new DefaultItemAnimator());
        mStructuralInformationAdapter = new StructuralInformationAdapter(this);
        mRvStructuralInformation.setAdapter(mStructuralInformationAdapter);
    }

    @Override
    public void getDataSuccess(TradingInstitutionBasicinfoBean response) {
        if (response.getData() != null) {
            if (response.getData().getIpBasicInfomation() != null) {
                TradingInstitutionBasicinfoBean.DataBean.IpBasicInfomationBean bean = response.getData().getIpBasicInfomation();
                setViewData(bean);
                List<TradingInstitutionBasicinfoBean.DataBean.IpBasicInfomationShareListBean> list = response.getData().getIpBasicInfomationShareList();
                mStructuralInformationAdapter.addData(list);
            }
        }
    }



    private void setViewData(TradingInstitutionBasicinfoBean.DataBean.IpBasicInfomationBean bean) {
        mTvBusinessLicenseInformation1.setText(bean.getUnifiedSocialCreditCode());
        mTvBusinessLicenseInformation2.setText(bean.getCompanyName());
        mTvBusinessLicenseInformation3.setText(bean.getRegistrationNumber());
        mTvBusinessLicenseInformation4.setText(bean.getLegalRepresentative());
        mTvBusinessLicenseInformation5.setText(bean.getTypes());
        mTvBusinessLicenseInformation6.setText(DateUtils.getStrng_to_Times_ymdhms(bean.getDateOfEstablishment()));
        mTvBusinessLicenseInformation7.setText(bean.getRegisteredCapital());
        mTvBusinessLicenseInformation8.setText(DateUtils.getStrng_to_Times_ymdhms(bean.getApprovedDate()));
        mTvBusinessLicenseInformation9.setText(DateUtils.getStrng_to_Times_ymdhms(bean.getOperatingPeriodFrom()));
        mTvBusinessLicenseInformation10.setText(DateUtils.getStrng_to_Times_ymdhms(bean.getBusinessPeriodTill()));
        mTvBusinessLicenseInformation11.setText(bean.getRegistrationAuthority());
        mTvBusinessLicenseInformation12.setText(bean.getRegistrationStatus());
        mTvBusinessLicenseInformation13.setText(bean.getResidence());
        mTvBusinessLicenseInformation14.setText(bean.getBusinessScope());

        mTvOtherBasicInformation1.setText(bean.getContactPerson());
        mTvOtherBasicInformation2.setText(bean.getContactInfo());
        mTvOtherBasicInformation3.setText(bean.getWebsite());
    }

    @Override
    public void getDataFailed() {

    }
}
